# -*- coding: utf-8 -*-
"""
@Env 
@Time 2024/9/3 上午10:55
@Author yzpang
@Function: 模型推理接口
"""
import traceback

from ..entity.response import BaseResponse
from ..entity.request import InferenceMessage
from modelserver.configs.base_config import get_logger
from ..service import inference_service

logger = get_logger()


def mount_inference_routes(app):
    """
    挂载推理相关接口
    :param app:
    """

    app.post(path="/inference/text",
             tags=['inference text'],
             summary="推理单条数据",
             )(inference_text)


def inference_text(request: InferenceMessage) -> BaseResponse:
    logger.info(request)
    try:
        result = inference_service.inference_text(request)
        return BaseResponse(data=result)
    except Exception as e:
        traceback.print_exc()
        return BaseResponse(code=500, msg="failed", data=str(e))
